<?php

/**
 * This is the model class for table "{{booked}}".
 *
 * The followings are the available columns in table '{{booked}}':
 * @property integer $id
 * @property integer $user_id
 * @property string $first_name
 * @property string $last_name
 * @property integer $object_id
 * @property string $check_in
 * @property string $check_out
 * @property integer $guest
 * @property string $comment
 * @property integer $total_price
 * @property integer $status
 * @property integer $paid
 */
class Booked extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Booked the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{booked}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('check_in, check_out', 'required'),
			array('user_id, object_id, guest, total_price, status, paid', 'numerical', 'integerOnly'=>true),
			array('first_name, last_name', 'length', 'max'=>255),
			array('check_in,user_id, object_id, comment', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('first_name, last_name', 'required', 'on'=>'booking'),
			array('id, user_id, first_name, last_name, object_id, check_in, check_out, guest, comment, total_price, status, paid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user'	=>	array(self::BELONGS_TO, 'Users', 'user_id'),
			'object'	=>	array(self::BELONGS_TO, 'Object', 'object_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_id' => 'User',
			'first_name' => 'First Name',
			'last_name' => 'Last Name',
			'object_id' => 'Object',
			'check_in' => 'Check In',
			'check_out' => 'Check Out',
			'guest' => 'Guest',
			'comment' => 'Comment',
			'total_price' => 'Total Price',
			'status' => 'Status',
			'paid' => 'Paid',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('object_id',$this->object_id);
		$criteria->compare('check_in',$this->check_in,true);
		$criteria->compare('check_out',$this->check_out,true);
		$criteria->compare('guest',$this->guest);
		$criteria->compare('comment',$this->comment,true);
		$criteria->compare('total_price',$this->total_price);
		$criteria->compare('status',$this->status);
		$criteria->compare('paid',$this->paid);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}